package com.smart.common.handler;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.smart.common.entities.core.BaseEnum;

import java.io.IOException;
import java.util.Map;

/**
 * 将枚举序列化成功JSON格式的对象
 *
 * @author 夏绪秋
 * @date 2022-09-22
 */
public class BaseEnumSerializer extends JsonSerializer<BaseEnum> {

    @Override
    public void serialize(BaseEnum baseEnum, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        Map<String, String> label = Map.of(
                "label", baseEnum.getLabel(),
                "value", baseEnum.getValue(),
                "theme", baseEnum.getTheme()
        );
        gen.writeObject(label);
    }

}